package com.example.administrator.waitan.find.read;

import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.administrator.waitan.R;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/1/14.
 */
public class ReadViewPagerAdapter extends PagerAdapter {
    private Context context;
    private ArrayList<ReadInfo> data;
    private ReadInfo info;

    public ReadViewPagerAdapter(Context context, ArrayList<ReadInfo> data) {
        this.context = context;
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.viewpager_read, null);
        TextView title = (TextView) view.findViewById(R.id.tv_read_title);
        TextView author = (TextView) view.findViewById(R.id.tv_read_author);
        TextView editor = (TextView) view.findViewById(R.id.tv_read_editor);
        TextView content = (TextView) view.findViewById(R.id.tv_read_content);
        info = data.get(position);
        title.setText(info.getTitle());
        author.setText(info.getAuthor());
        editor.setText(info.getEditor());
        content.setText(info.getContent());
        ImageView authorHead = (ImageView) view.findViewById(R.id.iv_read_author);
        authorHead.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent goReadAurhor = new Intent(context,ReadAuthorActivity.class);
                goReadAurhor.putExtra("author",data.get(position).getAuthor());
                goReadAurhor.putExtra("career",data.get(position).getCareer());
                goReadAurhor.putExtra("review",data.get(position).getReview());
                context.startActivity(goReadAurhor);
//
            }
        });
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
    }


}
